package com.qcby.system.api.factory;


import com.qcby.common.core.domain.Result;
import com.qcby.system.api.domain.SysUserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.qcby.system.api.RemoteUserService;
import com.qcby.system.api.model.LoginUser;

/**
 * 用户服务降级处理
 * 
 * @author qcby
 */
@Component
@Slf4j
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public Result<LoginUser> getUserInfo(String username, String source)
            {
                return Result.getServiceError("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public Result<Boolean> registerUserInfo(SysUserDTO sysUser, String source)
            {
                return Result.getServiceError("注册用户失败:" + throwable.getMessage());
            }
        };
    }
}
